// store/index.js
import { defineStore } from 'pinia'

// 定义并导出 store
export const useStore = defineStore('main', {
  state: () => ({
    token: uni.getStorageSync('token') || '',
    isLogin: !!uni.getStorageSync('token')
  }),
  actions: {
    // 登录成功
    loginSuccess(token) {
      this.token = token // 测试用token
      this.isLogin = true
      uni.setStorageSync('token', this.token)
    },
    // 退出登录
    logout() {
      this.token = ''
      this.isLogin = false
      uni.removeStorageSync('token')
    }
  }
})